package com.wqj.kyee.gps.nav

import android.os.Bundle
import android.view.View
import com.amap.api.navi.AMapNaviView
import com.amap.api.navi.enums.NaviType
import com.wqj.kyee.gps.R
import org.jetbrains.anko.find
import android.content.Intent



class MapNavActivity : BaseNavActivity() {
    var endPointLat: Double = 0.0
    var endPointLng: Double = 0.0
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_map_nav)
        mAMapNaviView = find<AMapNaviView>(R.id.navi_view)
        mAMapNaviView.onCreate(savedInstanceState)
        mAMapNaviView.setAMapNaviViewListener(this)

        val options = mAMapNaviView.viewOptions
        options.isLayoutVisible = true
        mAMapNaviView.viewOptions = options
        mAMapNaviView.naviMode = AMapNaviView.CAR_UP_MODE

        //取得从上一个Activity当中传递过来的Intent对象
        val intent = getIntent()
        //从Intent当中根据key取得value
        if (intent != null) {
            val value = intent.getStringExtra("key")
            endPointLat = intent.getDoubleExtra("endPointLat", 34.341568)
            endPointLng = intent.getDoubleExtra("endPointLng", 108.940174)
        }
    }

    fun northUp(view: View) {
        mAMapNaviView.naviMode = AMapNaviView.NORTH_UP_MODE
    }

    fun carUp(view: View) {
        mAMapNaviView.naviMode = AMapNaviView.CAR_UP_MODE
    }

    override fun onInitNaviSuccess() {
        super.onInitNaviSuccess()
        /**
         * 方法: int strategy=mAMapNavi.strategyConvert(congestion, avoidhightspeed, cost, hightspeed, multipleroute); 参数:
         *
         * @congestion 躲避拥堵
         * @avoidhightspeed 不走高速
         * @cost 避免收费
         * @hightspeed 高速优先
         * @multipleroute 多路径
         *
         * 说明: 以上参数都是boolean类型，其中multipleroute参数表示是否多条路线，如果为true则此策略会算出多条路线。
         * 注意: 不走高速与高速优先不能同时为true 高速优先与避免收费不能同时为true
         */
        var strategy = 0
        try {
            //再次强调，最后一个参数为true时代表多路径，否则代表单路径
            strategy = mAMapNavi.strategyConvert(true, false, false, false, false)
        } catch (e: Exception) {
            e.printStackTrace()
        }

        mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy)

    }

    override fun onCalculateRouteSuccess(ids: IntArray) {
        super.onCalculateRouteSuccess(ids)
        mAMapNavi.startNavi(NaviType.EMULATOR)
    }

}
